<?php

// load trades

$sql = "SELECT trade, url FROM trades ORDER BY trade";
$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());
$rows = mysql_num_rows($query);

$max_per_column = ceil($rows / 4);

$col_2_start = $max_per_column + 1;
$col_2_end = $max_per_column * 2;

$col_3_start = ($max_per_column * 2) + 1;
$col_3_end = $max_per_column * 3;

$col_4_start = ($max_per_column * 3) + 1;

$i = 1;

while($trades_rs=mysql_fetch_assoc($query)){

$trades_cols.=($i == 1 || $i == $col_2_start || $i == $col_3_start)? '<ul>'."\r\n" : '' ;

$trades_cols.=($i == $col_4_start) ? '<ul>'."\r\n" : '' ;

$trades_cols.='<li><a href="/tradesmen/'.$trades_rs['url'].'/all-areas" title="Local '.htmlentities($trades_rs['trade']).'">'.htmlentities($trades_rs['trade']).'</a></li>'."\r\n";

$trades_cols.=($i == $max_per_column || $i == $col_2_end || $i == $col_3_end || $i == $rows)? '</ul>'."\r\n" : '' ;

$i++;

}

?>
</div>

	<footer>
	
	<div class="layout_container">
	<div id="footer_container">

		<nav>
		
		<ul>
		<li><a href="/">Home</a></li>
		<li><a href="/post-a-job">Post a job</a></li>
		<li><a href="/tradesmen">Tradesmen</a></li>
		<li><a href="/view-jobs">Jobs</a></li>
		<li><a href="/help">Help</a></li>
		<li><a href="/blog">Blog</a></li>
		<li><a href="/contact-us">Contact</a></li>
		<li><a href="/terms">Terms</a></li>
		<li><a href="/privacy">Privacy</a></li>
		<li><a href="/directory">Business Directory</a></li>
		</ul>
		
		<?php echo $trades_cols; ?>
		
		</nav>
		
		<a href="http://www.facebook.com/pages/I-Want-A-Tradesman/194775973907678" class="social_link" id="footer_facebook" target="_blank"><img src="/images/facebook_large.png" alt="Join us on facebook"></a>
		<a href="http://twitter.com/iwantatradesman" class="social_link" id="footer_twitter" target="_blank"><img src="/images/twitter_large.png" alt="Follow us on twitter"></a>
		
		<p>I Want A Tradesman &copy; <?php echo date("Y"); ?></p>
		
	</div>
	</div>

	</footer>
	
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-2877634-4");
pageTracker._trackPageview();
} catch(err) {}</script>
	
</body>
</html>